package com.authine.cloudpivot.app.openapi.service;

import com.authine.cloudpivot.app.openapi.dto.GenerateTokenRes;
import com.authine.cloudpivot.app.openapi.dto.OpenUserInfoRes;
import com.authine.cloudpivot.app.openapi.executor.GenerateOpenApiTokenExe;
import com.authine.cloudpivot.app.openapi.executor.GetUserInfoQry;
import org.springframework.stereotype.Service;

/**
 * @author lifuchun
 */
@Service
public class OpenApiServiceImpl {


    private final GenerateOpenApiTokenExe generateOpenApiTokenExe;
    private final GetUserInfoQry getUserInfoQry;

    public OpenApiServiceImpl(GenerateOpenApiTokenExe generateOpenApiTokenExe, GetUserInfoQry getUserInfoQry) {
        this.generateOpenApiTokenExe = generateOpenApiTokenExe;
        this.getUserInfoQry = getUserInfoQry;
    }

    /**
     * 生成令牌
     *
     * @param appKey 应用key
     * @param userId 用户id
     * @param nonce  随机码
     * @param sign   签名
     * @return 生成令牌信息
     */
    public GenerateTokenRes generateToken(String appKey, String userId, String nonce, String sign) {

        return generateOpenApiTokenExe.execute(appKey, userId, nonce, sign);
    }

    /**
     * 获取用户信息
     *
     * @param openToken 派发的token
     * @return 返回的用户信息
     */
    public OpenUserInfoRes getUserInfo(String openToken) {

        return getUserInfoQry.execute(openToken);

    }
}
